package com.ivanceras.client.view;

import java.io.Serializable;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.IsSerializable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class ChoiceEdit implements IsSerializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public boolean isCorrect;
	public int questionNo;
	public TextBox textBox;
	RadioButton radioButton;
	HorizontalPanel widget;
	private boolean isOfficial = false;
	//There must have a constructor with no argument?
	public ChoiceEdit(){
		widget = new HorizontalPanel();
		radioButton = new RadioButton("q"+questionNo);
		HTML spacer = new HTML();
		spacer.setWidth("10px");
		textBox = new TextBox();
		textBox.setWidth("100%");
		widget.setWidth("80%");
		widget.add(radioButton);
		widget.add(spacer);
		widget.add(textBox);
		widget.setCellWidth(radioButton, "1%");
		widget.setCellWidth(spacer, "1%");
		widget.setCellWidth(textBox, "98%");
		radioButton.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				isCorrect = radioButton.getValue();
			}
			
		});
	}
	/**
	 * Is this choice official
	 * @param isOfficial
	 */
	public void setOfficial(boolean isOfficial){
		this.isOfficial = isOfficial;
		if(this.isOfficial){
			widget.setStyleName("choice-normal");
			radioButton.setEnabled(true);
		}else{
			widget.setStyleName("choice-new");
			radioButton.setEnabled(false);
		}
	}
	public boolean isOfficial(){
		return isOfficial;
	}
	public Widget getWidget(){
		return widget;
	}
	public String getText(){
		return textBox.getText();
	}
	public boolean isCorrect(){
		return this.isCorrect;
	}
}
